<html XMLNS:AI>
<head>
<?import namespace="AI" implementation="aiTree.htc" />
<link href="dialog.css" rel="stylesheet" type="text/css">
<title>Insert Link</title>
<script>
	var d = document;
	var lnk = dialogArguments;
	var doc;
	var http;
			
	function init() {
		if( lnk.get ) {
			http = new ActiveXObject( 'Msxml2.XMLHTTP' );
			http.open( 'GET', lnk.get, true );
			http.onreadystatechange = function() {
				if( http.readyState == 4 ) {
					doc = http.responseXML;
					if( ! doc.xml ) {
						doc.loadXML( '<root><pic name="-- no internal links defined --"/></root>' );
					}
					doc.setProperty( 'SelectionLanguage', 'XPath' );
					aiTree.data = doc.xml;
					http = null;
				}
			}
			http.send();
		}
	}
			
	onload = function() {
		init();
		url.value = lnk.href;

		for( var i = 0; i < tg.options.length; i++ ) {
			if( tg.options[i].text.match( lnk.target ) ) { tg.selectedIndex = i; }
		}

		var a = lnk.anchors;
		if( a.length ) {
			addOpt( '-- select an anchor --' );					
			for( var i = 0; i < a.length; i++ ) {
				addOpt( a[i].name );
			}
			an.onchange = function() {
				if( this.selectedIndex ) {
					url.value = '#' + this.options[this.selectedIndex].text;
				}
			}
		} else {
			addOpt( '-- no anchors defined --' );
		}
			
		aiTree.onchoose = function( e ) {
			url.value = e.href;
		}
		btnCan.onclick = function() {
			returnValue = null;
			close();
		}
		btnIns.onclick = function() {
			lnk.href = pro.value + url.value;
			lnk.target = tg.options[tg.selectedIndex].text;
			returnValue = lnk;
			close();
		}
	}

	function addOpt( v ) {
		var o = d.createElement( '<option>' );
		o.text = v;
		an.add( o );
	}
</script>
</head>
	<body>
		<table cellspacing="0" cellpadding="1">
			<tr>
				<td colspan="2" class="title">:: link to ::</td>
			</tr>
			<tr>
				<td align="right">
					url : 
				</td>
				<td colspan="2">
					<select name="pro">
						<option>
						<option value="http://">http://
						<option value="ftp://">ftp://
						<option value="mailto:">mailto:
					</select>
					<input id="url" size="35" style="text-align:left;">
				</td>
			</tr>
			<tr>
				<td align="right">
					target :
				</td>
				<td>
					<select id="tg">
						<option>_self
						<option>_blank
						<option>_parent
						<option>_top
					</select>
				</td>
			</tr>
			<tr>
				<td align="right">
					anchor : 
				</td>
				<td>
					<select id="an">
					</select>
				</td>
			</tr>
			<tr>
				<td colspan="2"><hr class="line"></td>
			</tr>
			<tr>
				<td align="right" valign="top">
					internal link :
				</td>
				<td valign="top">
					<AI:aiTree id="aiTree" />
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input id="btnCan" type="button" style="text-align:center;" value=":: cancel ::">
					<input id="btnIns" type="button" style="text-align:center;" value=":: insert ::">
				</td>
			</tr>
		</table>
	</body>
</html>